/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import java.util.Calendar;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.ipti.br.tag.util.CalendarUtil;
import org.ipti.br.tag.util.EncryptionUtil;
/**
 *
 * @author israel
 */
@Entity
public class Actor extends AbstractEntity {

    @Temporal(TemporalType.DATE)
    private Calendar activated;

    @Temporal(TemporalType.DATE)
    private Calendar deactivated;

    @Column(length=20)
    private String enrollment;

    @ManyToOne
    private Person person;

    @ManyToOne
    private Unity unity;

    @ManyToOne
    private Personage personage;
    
    @OneToMany(mappedBy = "actor",fetch= FetchType.LAZY,orphanRemoval=true)
    private List<ActorSchedule> actorSchedules;
    
    @OneToMany(mappedBy = "actor",fetch= FetchType.LAZY,orphanRemoval=true)
    private List<SimpleFrequency> simpleFrequencys;
    
    @Transient
    private List<Performance> performances;

    public Actor() {
        activated = Calendar.getInstance();
        deactivated = Calendar.getInstance();
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String hash = "" 
                    + ((this.getActivated() != null) ? CalendarUtil.getFormatedDate(this.getActivated()) : null)
                    + ((this.getDeactivated() != null) ? CalendarUtil.getFormatedDate(this.getDeactivated()) : null)
                    + ((this.getPerson() != null) ? this.getPerson().getId() : null)
                    + ((this.getUnity() != null) ? this.getUnity().getId() : null)
                    + ((this.getPersonage() != null) ? this.getPersonage().getId() : null);
            this.setId(Long.valueOf(EncryptionUtil.encrypt(hash).hashCode()));
        }
    }

    public Actor(Calendar activated, Calendar deactivated, Person person, Unity unity, Personage personage) {
        this.activated = activated;
        this.deactivated = deactivated;
        this.person = person;
        this.unity = unity;
        this.personage = personage;
    }

    public Calendar getActivated() {
        return activated;
    }

    public void setActivated(Calendar activated) {
        this.activated = activated;
    }

    public Calendar getDeactivated() {
        return deactivated;
    }

    public void setDeactivated(Calendar deactivated) {
        this.deactivated = deactivated;
    }

    public String getEnrollment() {
        return enrollment;
    }

    public void setEnrollment(String enrollment) {
        this.enrollment = enrollment;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public Personage getPersonage() {
        return personage;
    }

    public void setPersonage(Personage personage) {
        this.personage = personage;
    }

    public Unity getUnity() {
        return unity;
    }

    public void setUnity(Unity unity) {
        this.unity = unity;
    }

    public List<ActorSchedule> getActorSchedules() {
        return actorSchedules;
    }

    public void setActorSchedules(List<ActorSchedule> actorSchedules) {
        this.actorSchedules = actorSchedules;
    }

    public List<SimpleFrequency> getSimpleFrequencys() {
        return simpleFrequencys;
    }

    public void setSimpleFrequencys(List<SimpleFrequency> simpleFrequencys) {
        this.simpleFrequencys = simpleFrequencys;
    }

    public List<Performance> getPerformances() {
        return performances;
    }

    public void setPerformances(List<Performance> performances) {
        this.performances = performances;
    }
    
}
